package com.wangsanfei.ihg.wechat.controller;

import java.util.List;

import com.jfinal.aop.Clear;
import com.jfinal.core.ActionKey;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.wangsanfei.base.BaseController;
import com.wangsanfei.config.ConstConfig;
import com.wangsanfei.ihg.wechat.interceptor.AuthInterceptor;
import com.wangsanfei.ihg.wechat.model.Notice;
import com.wangsanfei.model.User;
import com.wangsanfei.vo.BaseVo;

public class IndexController extends BaseController{

	public void index(){
		redirect("/index.html");
	}
	
	@Clear(AuthInterceptor.class)
	@ActionKey("/manage")
	public void manage_index(){
		setAttr("nav", "index");
		try {
			User user=(User)getSession().getAttribute(ConstConfig.SESSION_USER);
			Record hotel=(Record)getSession().getAttribute(ConstConfig.SESSION_HOTEL);
			if(user==null&&hotel==null){
				//说明此时后台没有登录，前台可能登录了，所以清空session
				getSession().invalidate();
				renderJsp("/manage/login.jsp");
			}else{
				renderJsp("/manage/index.jsp");
			}
		} catch (Exception e) {
			//说明此时后台没有登录，前台可能登录了，所以清空session
			getSession().invalidate();
			renderJsp("/manage/login.jsp");
		}
	}
	
	@ActionKey("/manage/currentUser")
	public void manage_currentUser(){
		setAttr("nav", "currentUser");
		User user=(User)getSession().getAttribute(ConstConfig.SESSION_USER_TYPE);
		setAttr("nav", "currentUser");
		setAttr("vo", user);
		renderJsp("/manage/currentUser.jsp");
	}
	
	@ActionKey("/getIndexInfo")
	public void getIndexInfo(){
		
		List<Record> banners=Db.find("select * from t_file_info t where t.removed='0'"
				+ " and t.lx='1' order by t.createTime desc ");
		
		String lx=getPara("lx");
		Integer pageSize=getParaToInt("pageSize");
		Integer limitFrom=getParaToInt("limitFrom");
		
		List<Record> zx=Notice.dao.findByLx(lx,limitFrom,pageSize);
		
		Record data=new Record();
		data.set("banners", banners);
		data.set("zx", zx);
		
		BaseVo baseVo=new BaseVo();
		baseVo.setFlag(true);
		baseVo.setData(data);
		
		renderJson(baseVo);
	}
	
	
	
	
	
}
